package com.common.vo;


import java.io.Serializable;

import lombok.Data;

/**
 * 页面返回数据
 * @author yyq
 *
 */
@Data
public class Result<T> implements Serializable{

	private static final long serialVersionUID = 1L;
	
	/** 状态*/
	private Integer code;		 
	/** 提示*/
	private String msg;		 
	/** 返回的对象*/
	private T data;	 
	/** 成功是否*/
	private Boolean success;   
	/** 总数*/
	private Long count;  	 
	
	/**
	 * 成功码:200
	 */
	public static final int SUCCESS_STATE = 200;
	/**
	 * 成功码:0
	 */
	public static final int SUCCESS_CODE = 0;
	/**
	 * 失败码:500
	 */
	public static final int FAIL_STATE = 500;
	/**
	 * 失败码:1
	 */
	public static final int FAIL_CODE = 1;
	/**
	 * 成功提示
	 */
	public static final String SUCCESS_MSG = "操作成功";
	/**
	 * 失败提示
	 */
	public static final String FAIL_MSG = "操作失败";
	
	
	/**
	 * 成功操作
	 * @param msg
	 * @return
	 */
	public static <T> Result<T> success() {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(Result.SUCCESS_MSG);
		result.setSuccess(true);
		return result;
	}
	public static <T> Result<T> success(T data) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(Result.SUCCESS_MSG);
		result.setData(data);
		result.setSuccess(true);
		return result;
	}
	
	public static <T> Result<T> success(String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(msg);
		result.setSuccess(true);
		return result;
	}
	
	public static <T> Result<T> success(T data, String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_STATE);
		result.setMsg(msg);
		result.setData(data);
		result.setSuccess(true);
		return result;
	}
	
	public static <T> Result<T> success(T data, Long count) {
		Result<T> result = new Result<T>();
		result.setCode(Result.SUCCESS_CODE);
		result.setMsg(Result.SUCCESS_MSG);
		result.setData(data);
		result.setSuccess(true);
		result.setCount(count);
		return result;
	}
	
	
	/**
	 * 失败操作
	 * @param msg
	 * @return
	 */
	public static <T> Result<T> fail() {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(Result.FAIL_MSG);
		result.setSuccess(false);
		return result;
	}
	public static <T> Result<T> fail(T data) {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(Result.FAIL_MSG);
		result.setData(data);
		result.setSuccess(false);
		return result;
	}
	
	public static <T> Result<T> fail(String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(msg);
		result.setSuccess(false);
		return result;
	}
	
	public static <T> Result<T> fail(T data, String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_STATE);
		result.setMsg(msg);
		result.setData(data);
		result.setSuccess(false);
		return result;
	}
	
	public static <T> Result<T> failLay(String msg) {
		Result<T> result = new Result<T>();
		result.setCode(Result.FAIL_CODE);
		result.setMsg(msg);
		result.setSuccess(false);
		return result;
	}
	
}
